<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>项目需求</title>
	<link rel="icon" href="../../img/icon.png" type="image/x-icon"/>
	<link rel="stylesheet" type="text/css" href="../../css/mui.css"/>
	<link rel="stylesheet" type="text/css" href="../../css/mui.min.css"/>
	<link rel="stylesheet" type="text/css" href="../../css/app.css"/>
</head>
<body>
<!-- 顶部菜单 -->
<ul id="top">
	<li class="addBug back" onclick="mui.back();">返回</li>
	<li class="addBug">项目需求</li>
	<li class="addBug pub" onclick="jumpToMyProAdd()">新增</li>
</ul>
<!-- 主体 -->
<div style="height: 50px;"></div>
<div class="form">
	<h2>初始化需求编辑</h2>
	<textarea class="textareaEdit" id="detail" placeholder="项目初始化需求编辑"></textarea>
	<input type="button"  value="保存" onclick="setDetail()"/>
</div>
<div style="height: 50px;"></div>
<!-- 底部菜单 -->
<ul id="foot">
	<li class="noclick" onclick="jumpToIndex()">BUG</li>
	<li class="noclick" onclick="jumpToHistory()">历史</li>
	<li class="noclick" onclick="jumpToMore()">更多</li>
	<li onclick="jumpToMy()">我的</li>
</ul>
</body>
</html>


<script type="text/javascript" src="../../js/mui.min.js"></script>
<script type="text/javascript" src="../../js/app.js"></script>
<script type="text/javascript">
	var domain = getDomain();
	var token = getAdminToken();
	var proInfo = cacheGet(proInfoKey);
	(function($, owner) {
		getDetail();
	}(mui, window.app = {}));
	//需求获取
	function getDetail(){
		var proInfo = cacheGet(proInfoKey);
		if (proInfo && proInfo.proDetail) {
			mui("#detail")[0].innerHTML = proInfo.proDetail;
			return
		}
	}
	//需求编辑
	function setDetail(){
		var detail = mui("#detail")[0].value;
		if (!detail) {
			mui.toast('需求没填写！',{ 
				duration:'long', type:'div',
			});
			return
		}
		mui.ajax(domain+'/app/project/detail',{
			data:{
				token:token,
				proId:proInfo.proId,
				detail:detail
			},
			dataType:'json',//服务器返回json格式数据
			type:'post',//HTTP请求类型
			timeout:10000,//超时时间设置为10秒；
			// headers:{'Content-Type':'application/json'},
			headers:{'Content-Type':'application/x-www-form-urlencoded'}, 
			async: true,  //async: true || false, // 异步 || 同步
			crossDomain: true,  //强制跨域
			success:function(res){
				console.log('OK',res);
				// return
				if (res.code!=0) {
					mui.toast(res.msg+'！',{ 
						duration:'long', type:'div',
					});
					return
				}
				//更新缓存
				var proInfo = cacheGet(proInfoKey);
				proInfo.proDetail = detail;
				cacheSet(proInfoKey, proInfo);
				//成功提示
				mui.toast('修改成功！',{ 
					duration:'long', type:'div',
				});
				//页面跳转
				setTimeout(function(){
					jumpToMyProDetail();
				}, 2000);
			},
			error:function(xhr,type,errorThrown){
				// console.log('网络错误');
				mui.toast(xhr+type+'网络错误！',{
					duration:'long', type:'div',
				});
			}
		});
	}
</script>